package com.learn.chain.second;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class RealCall {

    private OkClient client;
    private Request request;

    public RealCall(OkClient client, Request request) {
        this.client = client;
        this.request = request;
    }

    public Response execute() {
        Response result = getResponseWithInterceptorChain();
        return result;
    }

    public Response getResponseWithInterceptorChain() {
        List<Interceptor> interceptors = new ArrayList<>();
        interceptors.addAll(client.interceptors());
        Interceptor.Chain chain = new RealInterceptorChain(interceptors, 0, this.request);
        return chain.proceed(request);
    }
}
